import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

export const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/index',
      meta: {
        wechatTitle: '分秒金融官网-财富机会,分秒必争,靠谱的商业投资理财平台'
      }
    },
    {
      path: '/index',
      component: require('../view'),
      alias: '/',
      redirect: '/home',
      children: [
        {
          path: 'home',
          component: resolve => require(['../view/home/index'], resolve),
          meta: {
            wechatTitle: '分秒金融官网-财富机会,分秒必争,靠谱的商业投资理财平台'
          }
        },
        {
          path: 'find',
          component: resolve => require(['../view/find/index'], resolve),
          meta: {
            wechatTitle: '发现'
          }
        },
        {
          path: 'invest',
          component: resolve => require(['../view/invest/index'], resolve),
          meta: {
            wechatTitle: '出借'
          }
        },
        {
          path: 'mine',
          component: resolve => require(['../view/mine/index'], resolve),
          meta: {
            wechatTitle: '我的'
          }
        }
      ]
    },
    {
      path: '/safeGuarntee',
      component: resolve => require(['../view/home/safeGuarntee'], resolve), // 安全保障
      meta: {
        wechatTitle: '安全保障'
      }
    },
    {
      path: '/greenHand',
      component: resolve => require(['../view/home/greenHand'], resolve), // 新手指引
      meta: {
        wechatTitle: '新手指引'
      }
    },
    {
      path: '/helpCenter',
      component: resolve => require(['../view/home/helpCenter'], resolve), // 帮助中心
      meta: {
        wechatTitle: '帮助中心'
      }
    },
    {
      path: '/aboutFenmiao',
      component: resolve => require(['../view/home/aboutFenmiao'], resolve), // 关于分秒
      meta: {
        wechatTitle: '关于分秒'
      }
    },
    {
      path: '/helpInfo/:id',
      component: resolve => require(['../view/home/helpInfo'], resolve), // 帮助中心的详情页面
      meta: {
        wechatTitle: '帮助中心'
      }
    },
    {
      path: '/goodDetail/:borrowOrder',
      component: resolve => require(['../view/common/goodDetail'], resolve),
      name: 'goodDetail',
      meta: {
        wechatTitle: '分秒金融官网-财富机会,分秒必争,靠谱的商业投资理财平台'
      }
    },
    {
      path: '/article/:uuid',
      component: resolve => require(['../view/find/article'], resolve), // 文章详情
      meta: {
        wechatTitle: '资讯'
      }
    },
    {
      path: '/profitCompute',
      component: resolve => require(['../view/find/profitCompute'], resolve), // 模拟收益
      meta: {
        wechatTitle: '模拟收益'
      }
    },
    {
      path: '/greenHandRed',
      component: resolve => require(['../view/find/greenHandRed'], resolve), // 新手红包
      meta: {
        wechatTitle: '新手红包'
      }
    },
    {
      path: '/statistics',
      component: resolve => require(['../view/mine/statistics'], resolve), // 资产统计
      meta: {
        requireAuth: true, // 是否需要登陆，用于路由拦截,
        wechatTitle: '资产统计'
      }
    },
    {
      path: '/redCard',
      component: resolve => require(['../view/mine/redCard'], resolve), // 红包卡卷
      meta: {
        requireAuth: true, // 是否需要登陆，用于路由拦截,
        wechatTitle: '红包卡卷'
      }
    },
    {
      path: '/login',
      component: resolve => require(['../view/mine/login'], resolve), // 登陆
      meta: {
        wechatTitle: '登录'
      }
    },
    {
      path: '/signup',
      component: resolve => require(['../view/mine/signup'], resolve), // 注册
      meta: {
        wechatTitle: '注册'
      }
    },
    {
      path: '/assetsmanagement',
      component: resolve => require(['../view/mine/assetsManagement'], resolve), // 资产管理
      meta: {
        requireAuth: true,
        wechatTitle: '资产管理'
      }
    },
    {
      path: '/paymentDetail/:name/:id',
      component: resolve => require(['../view/mine/paymentDetail'], resolve), // 回款明细
      meta: {
        requireAuth: true,
        wechatTitle: '回款明细'
      }
    },
    {
      path: '/capitalStream',
      component: resolve => require(['../view/mine/capitalStream'], resolve), // 资金流水
      meta: {
        requireAuth: true,
        wechatTitle: '资金流水'
      }
    },
    {
      path: '/presentationRecord',
      component: resolve => require(['../view/mine/presentationRecord'], resolve), // 提现记录
      meta: {
        requireAuth: true,
        wechatTitle: '提现记录'
      }
    },
    {
      path: '/rechargeRecord',
      component: resolve => require(['../view/mine/rechargeRecord'], resolve), // 充值记录
      meta: {
        requireAuth: true,
        wechatTitle: '充值记录'
      }
    },
    {
      path: '/safety',
      component: resolve => require(['../view/mine/safety'], resolve), // 安全认证
      meta: {
        requireAuth: true,
        wechatTitle: '安全认证'
      }
    },
    {
      path: '/bindCard',
      component: resolve => require(['../view/mine/bindCard'], resolve), // 银行卡
      meta: {
        requireAuth: true,
        wechatTitle: '银行卡'
      }
    },
    {
      path: '/addBankCard',
      component: resolve => require(['../view/mine/addBankCard'], resolve), // 添加银行卡
      meta: {
        requireAuth: true,
        wechatTitle: '添加银行卡'
      }
    },
    {
      path: '/myMessage',
      component: resolve => require(['../view/mine/myMessage'], resolve), // 我的消息
      meta: {
        requireAuth: true,
        wechatTitle: '我的消息'
      }
    },
    {
      path: '/inviteFriends',
      component: resolve => require(['../view/mine/inviteFriends'], resolve), // 邀请好友
      meta: {
        requireAuth: true,
        wechatTitle: '邀请好友'
      }
    },
    {
      path: '/investmentDetail/:borrowOrder',
      component: resolve => require(['../view/invest/investmentDetail'], resolve), // 投资详情页面
      meta: {
        requireAuth: true,
        wechatTitle: '出借详情'
      }
    },
    {
      path: '/rechargeMoney',
      component: resolve => require(['../view/mine/rechargeMoney'], resolve), // 充值页面
      meta: {
        requireAuth: true,
        wechatTitle: '充值'
      }
    },
    {
      path: '/successSign',
      component: resolve => require(['../view/invest/successSign'], resolve), // 签署成功
      meta: {
        wechatTitle: '恭喜您！签署成功'
      }
    },
    {
      path: '/goSign',
      component: resolve => require(['../view/common/goSign'], resolve), // 点击立即签署后跳转页面
      meta: {
        wechatTitle: '分秒金融'
      }
    },
    {
      path: '/successOpen',
      component: resolve => require(['../view/invest/successOpen'], resolve), // 开户成功后的页面
      meta: {
        wechatTitle: '恭喜您！开户成功'
      }
    },
    {
      path: '/withdrawals',
      component: resolve => require(['../view/mine/withdrawals'], resolve), // 提现
      meta: {
        requireAuth: true,
        wechatTitle: '提现'
      }
    },
    {
      path: '/serviceAgreement',
      component: resolve => require(['../view/other/serviceAgreement'], resolve), // 贷款服务协议
      meta: {
        wechatTitle: '贷款服务协议'
      }
    },
    {
      path: '/warn',
      component: resolve => require(['../view/other/warn'], resolve), // 风险提示
      meta: {
        wechatTitle: '风险提示书'
      }
    },
    {
      path: '/inviteRule',
      component: resolve => require(['../view/mine/inviteRule'], resolve), // 邀请规则
      meta: {
        wechatTitle: '邀请规则'
      }
    },
    {
      path: '/inviteHistory',
      component: resolve => require(['../view/mine/inviteHistory'], resolve), // 邀请记录
      meta: {
        requireAuth: true,
        wechatTitle: '邀请记录'
      }
    },
    {
      path: '/inviteDetail',
      component: resolve => require(['../view/mine/inviteDetail'], resolve), // 邀请扫码后的页面
      meta: {
        wechatTitle: '分秒金融'
      }
    },
    {
      path: '/thanksDetail',
      component: resolve => require(['../view/mine/thanksDetail'], resolve), // 答谢明细
      meta: {
        requireAuth: true,
        wechatTitle: '答谢明细'
      }
    },
    {
      path: '/nextThanksDetail',
      component: resolve => require(['../view/mine/nextThanksDetail'], resolve), // 预计下期发放
      meta: {
        requireAuth: true,
        wechatTitle: '预计下期发放'
      }
    },
    {
      path: '/signupAgreement',
      component: resolve => require(['../view/other/signupAgreement'], resolve), // 注册协议
      meta: {
        wechatTitle: '注册协议'
      }
    },
    {
      path: '/forgetPasswordStep1',
      component: resolve => require(['../view/mine/forgetPasswordStep1'], resolve), // 忘记密码 -> 步骤1 ↓
      meta: {
        wechatTitle: '找回密码'
      }
    },
    {
      path: '/forgetPasswordStep2/:phoneNum',
      component: resolve => require(['../view/mine/forgetPasswordStep2'], resolve), // 忘记密码 -> 步骤2 ↓
      meta: {
        wechatTitle: '找回密码'
      }
    },
    {
      path: '/forgetPasswordStep3/:loginName/:smsCode',
      component: resolve => require(['../view/mine/forgetPasswordStep3'], resolve), // 忘记密码 -> 步骤3 ↓
      meta: {
        wechatTitle: '找回密码'
      }
    },
    {
      path: '/activityInviteFriend',
      component: resolve => require(['../view/other/activityInviteFriend'], resolve), // 邀请好友
      meta: {
        wechatTitle: '邀请好友'
      }
    },
    {
      path: '/certificate',
      component: resolve => require(['../view/mine/certificate'], resolve), // 实名认证
      meta: {
        requireAuth: true,
        wechatTitle: '实名认证'
      }
    },
    {
      path: '/foriosandroid/certificate',
      component: resolve => require(['../view/foriosandroid/certificate'], resolve), // 实名认证for ios and android
      meta: {
        wechatTitle: '实名认证'
      }
    },
    {
      path: '/foriosandroid/goSign',
      component: resolve => require(['../view/foriosandroid/goSign'], resolve), // 立即签署for ios and android
      meta: {
        wechatTitle: '签署'
      }
    },
    {
      path: '/activity/yingdou',
      component: resolve => require(['../view/activity/yingdou/index'], resolve), // 影豆活动
      meta: {
        wechatTitle: '影豆'
      }
    },
    {
      path: '/activity/laborday',
      component: resolve => require(['../view/activity/laborday/index'], resolve), // 51活动
      meta: {
        wechatTitle: '五一专享 双重福利'
      }
    },
    {
      path: '/activity/fmjrpromote',
      component: resolve => require(['../view/activity/fmjrpromote'], resolve), // 活动推广
      meta: {
        wechatTitle: '新手福利'
      }
    },
    {
      path: '/activity/childrensday',
      component: resolve => require(['../view/activity/childrensDay'], resolve), // 6.1活动页面
      meta: {
        wechatTitle: '分秒金融 6.1福利狂欢'
      }
    },
    {
      path: '/activity/520',
      component: resolve => require(['../view/activity/520'], resolve), // 5.20活动页面
      meta: {
        wechatTitle: '分秒金融 懂你的小心思'
      }
    },
    {
      path: '/activityGreenHand',
      component: resolve => require(['../view/activity/newer'], resolve), // 新手页面改版
      meta: {
        wechatTitle: '分秒金融 新手福利'
      }
    },
    {
      path: '/activity/june',
      component: resolve => require(['../view/activity/june'], resolve), // 六月活动
      meta: {
        wechatTitle: '分秒金融 六月红包雨'
      }
    },
    {
      path: '/activity/august',
      component: resolve => require(['../view/activity/august'], resolve), // app活动页面（市场推广）
      meta: {
        wechatTitle: '分秒金融 八月福利全开放 最新电影免费看'
      }
    },
    {
      path: '/activity/nationalday',
      component: resolve => require(['../view/activity/nationalday'], resolve), // 国庆节活动
      meta: {
        wechatTitle: '分秒金融 十月好礼送不停 iphone8、小米2x等着你'
      }
    },
    {
      path: '/app',
      component: resolve => require(['../view/other/app'], resolve), // app下载页面
      meta: {
        wechatTitle: '分秒金融 App'
      }
    },
    {
      path: '/iosandroid',
      component: resolve => require(['../view/activity/appiosandroid'], resolve), // app活动页面
      meta: {
        wechatTitle: '分秒金融 App'
      }
    },
    {
      path: '/fmjrapp',
      component: resolve => require(['../view/activity/fmjrapp'], resolve), // app活动页面（市场推广）
      meta: {
        wechatTitle: '分秒金融 App'
      }
    },
    {
      path: '*',
      component: resolve => require(['../view/other/404'], resolve), // 404页面
      meta: {
        wechatTitle: '页面找不到了'
      }
    }
  ]
})
// 路由拦截 -> 需要进入有登陆权限的界面时，拦截跳转到login界面
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    if (Vue.prototype.$cookie.get('acctKey')) {
      next()
    } else {
      next({
        path: '/login',
        query: { redirect: to.fullPath }
      })
    }
  } else {
    next()
  }
})
